package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsTourismProjectActivitiesApplicantDetail;
import com.macro.mall.dto.BmsTourismProjectActivitiesApplicantParam;
import com.macro.mall.dto.BmsTourismProjectActivitiesParam;
import com.macro.mall.model.BmsTourismProjectActivitiesApplicant;
import com.macro.mall.model.BmsVolunteerRegistration;
import com.macro.mall.security.util.JwtTokenUtil;
import com.macro.mall.service.BmsTourismProjectActivitiesApplicantService;
import com.macro.mall.utils.ExcelUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.net.URLEncoder;
import java.util.List;

@Controller
@Api(tags = "BmsTourismProjectActivitiesApplicantController")
@Tag(name = "BmsTourismProjectActivitiesApplicantController", description = "文旅项目-活动")
@RequestMapping("/tourismProjectActivitiesApplicant")
public class BmsTourismProjectActivitiesApplicantController {

    @Autowired
    private BmsTourismProjectActivitiesApplicantService bmsTourismProjectActivitiesApplicantService;

    @ApiOperation("分页查询留言建议")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsTourismProjectActivitiesApplicant>> getList(@RequestBody BmsTourismProjectActivitiesApplicantParam bmsTourismProjectActivitiesApplicantParam) {
        List<BmsTourismProjectActivitiesApplicant> bmsTourismProjectActivitiesApplicantList = bmsTourismProjectActivitiesApplicantService.getList(bmsTourismProjectActivitiesApplicantParam);
        return CommonResult.success(CommonPage.restPage(bmsTourismProjectActivitiesApplicantList));
    }

    @ApiOperation("根据id获取留言建议信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsTourismProjectActivitiesApplicantDetail> getItem(@PathVariable Long id) {
        BmsTourismProjectActivitiesApplicantDetail bmsTourismProjectActivitiesApplicantDetail = bmsTourismProjectActivitiesApplicantService.getItem(id);
        return CommonResult.success(bmsTourismProjectActivitiesApplicantDetail);
    }
    
    @ApiOperation("分页查询留言建议")
    @RequestMapping(value = "/export", method = RequestMethod.POST)
    public void export(@RequestBody BmsTourismProjectActivitiesApplicantParam bmsTourismProjectActivitiesApplicantParam, HttpServletResponse response) throws Exception {
        List<BmsTourismProjectActivitiesApplicant> bmsTourismProjectActivitiesApplicantList = bmsTourismProjectActivitiesApplicantService.getExportList(bmsTourismProjectActivitiesApplicantParam);
    	String fileName = URLEncoder.encode("团队预约.xlsx", "UTF-8");
    	response.setCharacterEncoding("utf-8");
    	ExcelUtils.write(response, fileName, "团队预约", bmsTourismProjectActivitiesApplicantList, BmsTourismProjectActivitiesApplicant.class);
    }
}
